<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">供应商基本信息维护</span>
        <el-button style="float: right;" type="primary" @click="dialogOpen('add')">新增供应商</el-button>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="操作"
          width="120">
          <template scope="s">
            <div v-if="s.row.iscancel === 2">
              <div v-if="s.row.bxSupplierState !== 5">
                <el-button type="primary" v-if="s.row.bxSupplierState === 1" size="mini" @click="tableUpload(s.row)" round>提交</el-button>
                <el-button type="warning" size="mini" v-if="s.row.bxSupplierState !== 1" @click="dialogSearchOpen(s.row)" round>轨迹</el-button>
                <el-button type="danger" size="mini" v-if="s.row.bxSupplierState === 2 " style="margin-left: 5px" @click="tableRevert(s.row)" round>撤回</el-button>
                <el-tooltip placement="top">
                  <div slot="content">更多可用操作</div>
                  <el-popover
                    popper-class="demo-table-expand"
                    placement="right"
                    v-if="s.row.bxSupplierState !== 2"
                    title="更多可用操作"
                    trigger="click">
                    <slot name="content">
                      <div>
                        <el-button type="success" icon="el-icon-edit" v-if="s.row.bxSupplierState === 1 || s.row.bxSupplierState === 4" size="mini" @click="dialogOpen('PUT', s.row)">修改</el-button>
                        <el-button type="danger" v-if="USER.auth.indexOf('resources_information_disable')!==-1 && s.row.bxSupplierState === 4" size="mini" @click="tableLock(s.row)">禁用</el-button>
                        <el-button type="danger" icon="el-icon-delete"  v-if="USER.auth.indexOf('resources_information_delete')!==-1 && s.row.bxSupplierState === 1" size="mini" @click="tableDelete(s.row)">删除</el-button>
                      </div>
                    </slot>
                    <el-button slot="reference"
                               icon="el-icon-more"
                               round
                               size="mini"
                               class="__reference"></el-button>
                  </el-popover>
                </el-tooltip>
              </div>
              <div v-else>
                <el-button type="success" size="mini" @click="dialogOpen('PUT', s.row)" round>编辑</el-button>
                <el-tooltip placement="top">
                  <div slot="content">更多可用操作</div>
                  <el-popover
                    popper-class="demo-table-expand"
                    placement="right"
                    v-if="s.row.bxSupplierState !== 2"
                    title="更多可用操作"
                    trigger="click">
                    <slot name="content">
                      <div>
                        <el-button type="primary" size="mini" @click="tableUpload(s.row)">提交</el-button>
                        <el-button type="warning" size="mini" @click="dialogSearchOpen(s.row)">轨迹</el-button>
                      </div>
                    </slot>
                    <el-button slot="reference"
                               icon="el-icon-more"
                               round
                               size="mini"
                               class="__reference"></el-button>
                  </el-popover>
                </el-tooltip>
              </div>
            </div>
            <div v-else>
              <el-button type="success" size="mini" v-if="USER.auth.indexOf('resources_information_disable')!==-1" @click="tableLock(s.row)" round>启用供应商</el-button>
            </div>
          </template>
        </el-table-column>
        <el-form-item label="姓名" prop="bxSupplierName">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierName"
                    placeholder="姓名" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="流程状态" prop="bxSupplierState">
          <el-select v-model="autoVue_table_bxSupplierState" placeholder="流程状态">
            <el-option
              label="全部"
              value="">
            </el-option>
            <el-option
              label="已驳回"
              :value="5">
            </el-option>
            <el-option
              label="已审核"
              :value="4">
            </el-option>
            <el-option
              label="审核中"
              :value="3">
            </el-option>
            <el-option
              label="待审核"
              :value="2">
            </el-option>
            <el-option
              label="草稿"
              :value="1">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结算周期" prop="bxSupplierSetlecircle">
          <el-select v-model="autoVue_table_bxSupplierSetlecircle"
                     filterable
                     remote
                     placeholder="请选择结算周期">
            <el-option
              v-for="item in dialog.bxSupplierSetlecircle"
              :key="item.id"
              :label="item.text"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开户银行" prop="bxSupplierBank">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierBank"
                    placeholder="开户银行" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item prop="bxSupplierDepartmentid" label="所属部门">
          <el-cascader
            :options="DEPARTMENT.department"
            v-model="autoVue_table_bxSupplierDepartmentid"
            :show-all-levels="false"
            ref="departmentId"
            clearable
            filterable
            change-on-select
            :props="{
                  value: 'key',
                }"
            placeholder="所属部门"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="可用操作"
                      v-if="USER.auth.indexOf('resources_information_export')!==-1"
                      prop="multiSelect">
          <el-row>
            <el-col :span="8">
              <el-button size="small" type="primary" @click="download('')">条件导出</el-button>
            </el-col>
          </el-row>
        </el-form-item>
        <!--
        <el-form-item label="账户名称" prop="bxSupplierAccount">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierAccount"
                    placeholder="账户名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="开户行" prop="bxSupplierBank">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierBank"
                    placeholder="开户行" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="银行账号" prop="bxSupplierBankaccount">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierBankaccount"
                    placeholder="银行账号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="供应商编码" prop="bxSupplierCode">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierCode"
                    placeholder="供应商编码" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="签订合同" prop="bxSupplierIscontract">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierIscontract"
                    placeholder="是否签订合同" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="联系方式" prop="bxSupplierPhone">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierPhone"
                    placeholder="联系方式" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="结算周期" prop="bxSupplierSetlecircle">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierSetlecircle"
                    placeholder="结算周期" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="bxSupplierState">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierState"
                    placeholder="状态" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="一级分类" prop="bxSupplierTypeF">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierTypeF"
                    placeholder="一级分类" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="二级分类" prop="bxSupplierTypeS">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bxSupplierTypeS"
                    placeholder="二级分类" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        -->
      </s-table>
    </el-card>
    <s-dialog :dialog="dialog">
      <p slot="title">{{dialog.title}}供应商 <span
        v-if="dialog.title === '修改'">供应商名称：{{dialog.row.bxSupplierName}}</span></p>
      <s-form :form="formDialog" ref="formDialog">
        <el-row>
          <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
            <el-form-item prop="bxSupplierName" label="供应商姓名">
              <el-input
                type="text"
                v-model="formDialog.bxSupplierName"
                placeholder="供应商姓名"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
            <el-form-item prop="bxSupplierDepartmentid" label="所属部门">
              <el-cascader
                :options="DEPARTMENT.department"
                v-model="formDialog.bxSupplierDepartmentid"
                :show-all-levels="false"
                ref="bxSupplierDepartmentid"
                clearable
                filterable
                change-on-select
                :props="{
                  value: 'key',
                }"
                placeholder="所属部门"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
            <el-form-item prop="workflowConfigId" label="所属流程">
              <el-select
                filterable
                v-model="formDialog.workflowConfigId"
                placeholder="请选择">
                <el-option
                  v-for="item in dialog.workflowConfigId"
                  :key="item.id"
                  :label="item.processName + '   ' +  item.departmentName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
            <el-form-item prop="bxSupplierPhone" label="联系方式">
              <el-input
                type="text"
                v-model="formDialog.bxSupplierPhone"
                placeholder="联系方式"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: formDialog.bxSupplierIsinvoice === 2 ? 5 : 7, offset: 0}">
            <el-form-item prop="bxSupplierIsinvoice" label="提供发票">
              <el-select v-model="formDialog.bxSupplierIsinvoice" placeholder="请选择">
                <el-option label="否" :value="1"></el-option>
                <el-option label="是" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 5, offset: 1}" class="" v-if="formDialog.bxSupplierIsinvoice === 2">
            <el-form-item prop="bxSupplierInvoicetype" label="发票类型">
              <el-select filterable v-model="formDialog.bxSupplierInvoicetype" placeholder="请选择">
                <el-option
                  v-for="item in INFORMATION.bxSupplierInvoicetype"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: formDialog.bxSupplierIsinvoice === 2 ? 5 : 7, offset: 1}" class="">
            <el-form-item prop="bxSupplierTypeF" label="一级分类">
              <el-select filterable v-model="formDialog.bxSupplierTypeF" placeholder="请选择">
                <el-option
                  v-for="item in INFORMATION.bxSupplierTypeF"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: formDialog.bxSupplierIsinvoice === 2 ? 5 : 7, offset: 1}" class="">
            <el-form-item prop="bxSupplierTypeS" label="二级分类">
              <el-select filterable v-model="formDialog.bxSupplierTypeS" placeholder="请选择">
                <el-option
                  v-for="item in INFORMATION.bxSupplierTypeS"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: formDialog.bxSupplierIscontract === 2 ? 5 : 11, offset: 0}" class="">
            <el-form-item prop="bxSupplierSetlecircle" label="结算周期">
              <el-select filterable v-model="formDialog.bxSupplierSetlecircle" placeholder="请选择">
                <el-option
                  v-for="item in dialog.bxSupplierSetlecircle"
                  :key="item.id"
                  :label="item.text"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: formDialog.bxSupplierIscontract === 2 ? 5 : 11, offset: 1}" class="">
            <el-form-item prop="bxSupplierIscontract" label="签订合同">
              <el-select v-model="formDialog.bxSupplierIscontract" placeholder="请选择">
                <el-option label="否" :value="1"></el-option>
                <el-option label="是" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 5, offset: 1}" class="" v-if="formDialog.bxSupplierIscontract === 2">
            <el-form-item prop="bxSupplierContracttime_start" label="合同开始">
              <el-date-picker
                v-model="formDialog.bxSupplierContracttime_start"
                placeholder="合同开始时间"
                :clearable="false">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 5, offset: 1}" class="" v-if="formDialog.bxSupplierIscontract === 2">
            <el-form-item prop="bxSupplierContracttime_end" label="合同结束">
              <el-date-picker
                v-model="formDialog.bxSupplierContracttime_end"
                placeholder="合同结束时间"
                :clearable="false">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 7, offset: 0}" class="">
            <el-form-item prop="bxSupplierAccount" label="账户名称">
              <el-input
                type="text"
                v-model="formDialog.bxSupplierAccount"
                placeholder="账户名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item prop="bxSupplierBank" label="开户行">
              <el-input
                type="text"
                v-model="formDialog.bxSupplierBank"
                placeholder="开户行"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 7, offset: 1}" class="">
            <el-form-item prop="bxSupplierBankaccount" label="银行账号">
              <el-input
                type="text"
                v-model="formDialog.bxSupplierBankaccount"
                placeholder="银行账号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="bxSupplierOilcard" label="油卡比例">
              <el-input
                type="text"
                v-model="formDialog.bxSupplierOilcard"
                @change="bxSupplierOilcardWatch"
                placeholder="油卡比例">
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="bxSupplierCash" label="现金比例">
              <el-input
                type="text"
                v-model="formDialog.bxSupplierCash"
                @change="bxSupplierCashWatch"
                placeholder="现金比例">
                <template slot="append">%</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 23, offset: 0}" class="">
            <el-form-item prop="remarks" label="备注">
              <el-input
                type="textarea"
                :rows="2"
                v-model="formDialog.remarks"
                placeholder="备注"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogUpload">
      <p slot="title">申请审核供应商 <span v-if="dialogUpload.row.bxSupplierName">供应商名称：{{dialogUpload.row.bxSupplierName}}</span></p>
      <s-form :form="formDialogUpload" ref="formDialogUpload">
        <el-row>
          <el-col :xs="24" :lg="{span: 23, offset: 0}" class="">
            <el-form-item prop="userId" label="审核人">
              <el-select v-model="formDialogUpload.userId"
                         filterable
                         placeholder="请选择">
                <el-option
                  v-for="item in dialogUpload.userId"
                  :key="item.id"
                  :label="item.name + '   ' + item.orgName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogUploadSave">保存</el-button>
    </s-dialog>
    <process ref="process"></process>
  </div>
</template>

<script>
  import {AutoVue, AutoPromise} from '~/plugins/Tools';

  function __form () {
    return {
      id: {value: '', rule: [], cRemarks: ''},
      remarks: {value: '', rule: [], cRemarks: ''},
      bxSupplierName: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierDepartmentid: {value: [], rule: ['vNull__change'], cRemarks: ''},
      bxSupplierCode: {value: '', rule: ['vNull'], cRemarks: '供应商'},
      bxSupplierSelfno: {value: '', rule: ['vNull', 'vNumber'], cRemarks: '供应商'},
      workflowConfigId: {value: '', rule: ['vNull__change'], cRemarks: ''},
      bxSupplierPhone: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierTypeF: {value: '', rule: ['vNull__change'], cRemarks: '供应商'},
      bxSupplierTypeS: {value: '', rule: ['vNull__change'], cRemarks: '供应商'},
      bxSupplierSetlecircle: {value: '', rule: ['vNull__change'], cRemarks: ''},
      bxSupplierIscontract: {value: '', rule: ['vNull'], cRemarks: '供应商'},
      bxSupplierContracttime_start: {value: [], rule: ['vNull__change'], type: 'Date'},
      bxSupplierContracttime_end: {value: [], rule: ['vNull__change'], type: 'Date'},
      bxSupplierAccount: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierBank: {value: '', rule: ['vNull'], cRemarks: ''},
      bxSupplierBankaccount: {value: '', rule: ['vNull', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
      bxSupplierOilcard: {value: '', rule: ['vNull', 'vNumber', 'vNumber100'], cRemarks: '供应商，油卡+现金=100%'},
      bxSupplierCash: {value: '', rule: ['vNull', 'vNumber', 'vNumber100'], cRemarks: '供应商，油卡+现金=100%'},
      bxSupplierIsinvoice: {value: '', rule: ['vNull'], cRemarks: '供应商'},
      bxSupplierInvoicetype: {value: '', rule: ['vNull__change'], cRemarks: '供应商'},
      bxSupplierState: {value: '', rule: [], cRemarks: ''},
    };
  }
  function __formDialogUpload () {
    return {
      userId: { value: '', rule: ['vNull'], cRemarks: '' },
    };
  }

  export default AutoVue({
    data: {
      table: {
        column: [
          {
            label: '供应商名称',
            prop: 'bxSupplierName',
            minWidth: '150px',
            cRemarks: '',
            search: true,
          },
          {
            label: '供应商编码',
            prop: 'bxSupplierCode',
            minWidth: '100px',
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '所属部门',
            prop: 'bxSupplierDepartmentname',
            searchName: 'bxSupplierDepartmentid',
            searchAfter: function (value) {
              return value.reverse()[0];
            },
            searchInitValue: function () {
              return [];
            },
            type: 'custom',
            search: true,
            minWidth: '220px',
            cRemarks: '',
          },
          {
            label: '联系方式',
            prop: 'bxSupplierPhone',
            minWidth: '100px',
            cRemarks: '',
            search: true,
          },
          { label: '流程状态',
            prop: 'bxSupplierState',
            minWidth: '0px',
            elTag: {
              filterType (type) {
                switch (type) {
                case 1:
                  return 'info';
                case 2:
                  return 'info';
                case 3:
                  return 'primary';
                case 4:
                  return 'success';
                case 5:
                  return 'danger';
                }
              },
            },
            formatter: (row, column) => {
              let step = parseInt(row[column.property || column]);
              switch (step) {
              case 1:
                return '草稿';
              case 2:
                return '待审核';
              case 3:
                return '审核中';
              case 4:
                return '已审核';
              case 5:
                return '已驳回';
              }
            },
            cRemarks: '',
            search: true },
          {
            label: '一级分类',
            prop: 'show_bxSupplierTypeF',
            minWidth: '0px',
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '更新人',
            prop: 'updateUserName',
            minWidth: '0px',
            cRemarks: '不用填写',
            search: false,
          },
          {
            label: '二级分类',
            prop: 'show_bxSupplierTypeS',
            minWidth: '0px',
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '结算周期',
            prop: 'show_bxSupplierSetlecircle',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '签订合同',
            prop: 'bxSupplierIscontract',
            minWidth: '0px',
            formatter: (row, column) => {
              return parseInt(row[column.property || column]) === 1 ? '否' : '是';
            },
            cRemarks: '供应商',
            search: true,
          },
          {
            label: '合同开始',
            prop: 'bxSupplierContracttime_start',
            minWidth: '0px',
            cRemarks: '供应商',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
          },
          {
            label: '合同结束',
            prop: 'bxSupplierContracttime_end',
            minWidth: '0px',
            cRemarks: '供应商',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 3);
            },
          },
          {
            label: '账户名称',
            prop: 'bxSupplierAccount',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '开户行',
            prop: 'bxSupplierBank',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '银行账号',
            prop: 'bxSupplierBankaccount',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '油卡比例',
            prop: 'bxSupplierOilcard',
            minWidth: '0px',
            formatter: (row, column) => {
              return (row[column.property || column] * 100).toFixed(2) + ' %';
            },
            cRemarks: '供应商，油卡+现金=100%',
            search: false,
          },
          {
            label: '现金比例',
            prop: 'bxSupplierCash',
            minWidth: '0px',
            formatter: (row, column) => {
              return (row[column.property || column] * 100).toFixed(2) + ' %';
            },
            cRemarks: '供应商，油卡+现金=100%',
            search: false,
          },
          {
            label: '提供发票',
            prop: 'bxSupplierIsinvoice',
            minWidth: '0px',
            formatter: (row, column) => {
              return parseInt(row[column.property || column]) === 1 ? '否' : '是';
            },
            cRemarks: '供应商',
            search: false,
          },
          {
            label: '发票类型',
            prop: 'show_bxSupplierInvoicetype',
            minWidth: '0px',
            cRemarks: '供应商',
            search: false,
          },
          {
            label: '状态',
            prop: 'show_bxSupplierState',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '备注',
            prop: 'remarks',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
        ],
        key: 'id',
        url: '/supplier/searchByPage',
        tableColumn: 5,
        muti: false,
      },
      formDialog: __form(),
      dialog: {
        title: '新增',
        bxSupplierSetlecircle: [],
        workflowConfigId: [],
        bxSupplierDepartmentid: [],
        row: {},
        width: '80%',
      },
      dialogUpload: {
        row: {},
        ids: [],
        userId: [],
      },
      formDialogUpload: __formDialogUpload(),
    },
    transition: 'slide-fade-bottom',
    head: {
      'title': '供应商基本信息维护',
      'meta': [
        {'hid': 'description', 'name': 'description', 'content': '乐速科技平台 资源管理 查看供应商基本信息维护'},
      ],
    },
    store: [
      'USER',
      'USER_user',
      'INFORMATION',
      'DEPARTMENT',
      'DICTIONARY_information',
    ],
    methods: {
      download (row) {
        let tableRef = 'table';

        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将导出供应商。', '确认导出？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(async _ => {
            try {
              let option = Object.assign({}, this['autoVue_' + tableRef]);
              await this.p({
                url: '/supplier/export',
                method: 'post',
                responseType: 'blob',
                data: {
                  ids,
                  ...option,
                },
              });
            } catch (err) {
              console.log(err);
            }
          })
          .catch(_ => {
          });
      },
      tableRevert (row) {
        this.$prompt('撤回此供应商原因', '确认撤回？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
        }).then(async ({value}) => {
          await this.post('/workflowConfig/revokeWorkflowProcess', {
            id: row.id,
            auditorNote: value,
          });
          this.tableWatch('table');
        });
      },
      tableDelete (row) {
        let tableRef = 'table';

        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this[tableRef].multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm('您将删除供应商。', '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        }).then(async () => {
          await this.del('/supplier', {
            data: ids,
          });
          this.tableWatch(tableRef);
        });
      },
      tableLock (row) {
        let tableRef = 'table';

        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this[tableRef].multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.$confirm(`您将${row.iscancel === 2 ? '禁用' : '启用'}供应商。`, '是否确认？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        }).then(async () => {
          await this.get('/supplier/iscancel/' + row.id);
          this.tableWatch(tableRef);
        });
      },
      tableUpload (row) {
        let tableRef = 'table';

        let ids = [];
        if (row) {
          ids.push(row.id);
        } else {
          if (this[tableRef].multipleSelection.length < 1) {
            return this.$alert('您还未选择，请您至少选择一个！', '提示');
          }
          this[tableRef].multipleSelection.forEach(item => {
            ids.push(item.id);
          });
        }
        this.dialogUploadOpen(ids, row);
      },

      async dialogOpen (type, more) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        await AutoPromise([
          async () => {
            if (!this.DICTIONARY_information) {
              await this.USE('DICTIONARY_information');
            }
          },
          async () => {
            this.dialog.bxSupplierSetlecircle = await this.get('/setlecvcle/setlecycleList');
          },
          async () => {
            let {contentList} = await this.post('/workflowConfig/searchByPage', {
              'pageNumber': 1,
              'pageSize': 9999,
              'processType': 2,
            });
            this.dialog.workflowConfigId = contentList;
          },
          async () => {
            if (more && !more.bxSupplierDepartmentidOld) {
              more.bxSupplierDepartmentidOld = await this.get('/dictionaries/departmentIds/' + more.bxSupplierDepartmentid);
            }
          },
          async () => {
            if (!more) {
              this.formDialog.bxSupplierDepartmentid = await this.get('/dictionaries/departmentIds/' + this.USER_user.orgId[0]);
            }
          },
        ]);
        switch (type) {
        case 'ADD':
          this.dialog.title = '新增';
          this.formDialog.id = 0;
          break;
        case 'PUT':
          this.dialog.title = '修改';
          this.$nextTick(() => {
            this.formDialog = {
              ...this.formDialog,
              ...this.ObjectClone(__form(), more),
            };
            this.formDialog.bxSupplierDepartmentid = more.bxSupplierDepartmentidOld;
            this.formDialog.bxSupplierOilcard *= 100;
            this.formDialog.bxSupplierCash *= 100;
          });
          this.dialog.row = more;
          break;
        }
        this.dialog.visible = true;
      },
      dialogSave () {
        if (this.dialog.title === '新增') {
          this.VALIDATE('formDialog', async option => {
            if (option.bxSupplierIsinvoice === 1) {
              delete option.bxSupplierInvoicetype;
            }
            if (option.bxSupplierContracttime === 1) {
              delete option.bxSupplierContracttime_start;
              delete option.bxSupplierContracttime_end;
            }
            option.bxSupplierDepartmentid = option.bxSupplierDepartmentid[option.bxSupplierDepartmentid.length - 1];
            option.bxSupplierDepartmentname = this.$refs.bxSupplierDepartmentid.currentLabels.join('-');
            option.bxSupplierOilcard /= 100;
            option.bxSupplierCash /= 100;
            try {
              await this.post('/supplier', option);
              this.dialog.dialogInit.call(this);
              this.tableWatch('table');
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          });
        } else {
          this.VALIDATE('formDialog', async option => {
            if (option.bxSupplierIsinvoice === 1) {
              delete option.bxSupplierInvoicetype;
            }
            if (option.bxSupplierContracttime === 1) {
              delete option.bxSupplierContracttime_start;
              delete option.bxSupplierContracttime_end;
            }
            option.bxSupplierOilcard /= 100;
            option.bxSupplierCash /= 100;
            option.bxSupplierDepartmentid = option.bxSupplierDepartmentid[option.bxSupplierDepartmentid.length - 1];
            option.bxSupplierDepartmentname = this.$refs.bxSupplierDepartmentid.currentLabels.join('-');
            try {
              await this.put('/supplier', option);
              this.dialog.dialogInit.call(this);
              this.tableWatch('table');
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          });
        }
      },

      async dialogUploadOpen (ids, row) {
        let {contentList} = await this.get('/workflowConfig/selectAuditors/' + row.id);
        this.dialogUpload.userId = contentList;
        this.dialogUpload.row = row;
        this.dialogUpload.ids = ids;
        this.dialogUpload.visible = true;
      },
      dialogUploadSave () {
        this.VALIDATE('formDialogUpload', async option => {
          if (option.bxSupplierIscontract !== 2) {
            delete option.bxSupplierContracttime_start;
            delete option.bxSupplierContracttime_end;
          }
          try {
            await this.post('/supplier/readyreview', {
              ...option,
              id: this.dialogUpload.row.id,
            });
            this.dialogUpload.dialogInit.call(this);
            this.tableWatch('table');
          } catch (err) {
            console.error(err);
          }
        });
      },
      dialogSearchOpen (row) {
        this.$refs.process.open(row);
      },
      bxSupplierOilcardWatch (data) {
        let step = parseFloat(data);
        if (step >= 0 && step <= 100) {
          this.formDialog.bxSupplierCash = (100 - step).toFixed(2);
        }
      },
      bxSupplierCashWatch (data) {
        let step = parseFloat(data);
        if (step >= 0 && step <= 100) {
          this.formDialog.bxSupplierOilcard = (100 - step).toFixed(2);
        }
      },
    },
    mounted: async function () {
      this.tableWatch('table');
      this.USE('DEPARTMENT');
      await AutoPromise([
        async () => {
          this.dialog.bxSupplierSetlecircle = await this.get('/setlecvcle/setlecycleList');
        },
      ]);
      console.log(this);
    },
  });
</script>
